package com.zhongxi.guoyuan.adapter.beautifulStore;

import android.content.Context;
import android.graphics.Paint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.application.MyApplication;
import com.zhongxi.guoyuan.entity.service.ServiceItemData;
import com.zhongxi.guoyuan.url.Url;
import com.zhongxi.guoyuan.utils.DataUtil;

import java.math.BigDecimal;
import java.util.List;

import static com.zhongxi.guoyuan.R.id.tvOrign;
import static com.zhongxi.guoyuan.R.id.tv_reward_coin;
import static com.zhongxi.guoyuan.R.id.tv_reward_yield;

/**
 * Created by Administrator on 2016/10/29.
 */

public class ProjectAdapter extends BaseAdapter {
    private List<ServiceItemData> data;
    private LayoutInflater mLayoutInflater;
    private Context context;

    public ProjectAdapter(Context context, List<ServiceItemData> data) {
        this.mLayoutInflater = LayoutInflater.from(context);
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
//        ViewHolder holder = null;
//        if (convertView == null) {
//            holder = new ViewHolder();
//            convertView = mLayoutInflater.inflate(R.layout.adapter_meirong, parent, false);
//            holder.ivImg = (ImageView) convertView.findViewById(R.id.ivImg);
//            holder.tvText = (TextView) convertView.findViewById(R.id.tvText);
//            holder.tvOriginPrice = (TextView) convertView.findViewById(R.id.tvOriginPrice);
//            holder.tvRewardCoin = (TextView) convertView.findViewById(R.id.tvRewardCoin);
//            holder.tvView = (TextView) convertView.findViewById(R.id.tvView);
//            holder.tvCash = (TextView) convertView.findViewById(R.id.tvCash);
//            holder.ivLimit = (ImageView) convertView.findViewById(R.id.ivLimit);
//            holder.tvTime = (TextView) convertView.findViewById(R.id.tv_time);
//            holder.yield_point = (TextView) convertView.findViewById(R.id.yield_point);
//            convertView.setTag(holder);
//        } else {
//            holder = (ViewHolder) convertView.getTag();
//        }
//        try {
//            ServiceItemData list = data.get(position);
//            if (null != list.getThumbnail() && !"".equals(list.getThumbnail())) {
//                Glide.with(context).load(Url.IMG_URL + list.getThumbnail()).placeholder(R.mipmap.iv_loading).fitCenter().into(holder.ivImg);
//            }
//            if (null != list.getName() && !"".equals(list.getName())) {
//                holder.tvText.setText(list.getName());
//            } else {
//                holder.tvText.setText("");
//            }
//            if (null != list.getPrice() && !"".equals(list.getPrice())) {
//                holder.tvCash.setText(list.getPrice() + "元");
//            } else {
//                holder.tvCash.setText("0元");
//            }
//            String multiplys = "";
//            if (null != list.getPrice() && !"".equals(list.getPrice())) {
//                if (Integer.parseInt(MyApplication.getInstance().getConsumebonusrate()) >= 30 && Integer.parseInt(MyApplication.getInstance().getConsumebonusrate()) <= 100) {
//                    String divide = DataUtil.divide(MyApplication.getInstance().getConsumebonusrate(), "100", 2, BigDecimal.ROUND_HALF_EVEN);
//                    multiplys = DataUtil.multiplys(list.getPrice(), divide);
//                } else {
//                    multiplys = "";
//                }
//            } else {
//                multiplys = "";
//            }
//            String backsilvernum="";
//            if (list.getBacksilvernum() != null && !"".equals(list.getBacksilvernum())) {
//                backsilvernum = list.getBacksilvernum();
//            } else {
//                backsilvernum="";
//            }
//            if ((!"".equals(multiplys) && !"0.00".equals(multiplys)) && (!"".equals(backsilvernum) && !"0".equals(backsilvernum))) {
//                holder.yield_point.setText("赠[" + multiplys + "消费点+");
//                holder.tvRewardCoin.setText(backsilvernum + "银币]");
//            } else if (("".equals(multiplys) || "0.00".equals(multiplys)) && (!"".equals(backsilvernum) && !"0".equals(backsilvernum))) {
//                holder.yield_point.setText("赠[");
//                holder.tvRewardCoin.setText(backsilvernum + "银币]");
//            } else if ((!"".equals(multiplys) && !"0.00".equals(multiplys)) && ("".equals(backsilvernum) || "0".equals(backsilvernum))) {
//                holder.yield_point.setText("赠[" + multiplys + "消费点");
//                holder.tvRewardCoin.setText("]");
//            } else {
//                holder.yield_point.setText("");
//                holder.tvRewardCoin.setText("");
//            }
//            if ("0".equals(list.getIslimited())) {
//                holder.ivLimit.setVisibility(View.GONE);
//            } else {
//                holder.ivLimit.setVisibility(View.VISIBLE);
//            }
//            if (null != list.getMarketprice() && !"".equals(list.getMarketprice())) {
//                holder.tvOriginPrice.setText("原价：" + list.getMarketprice());
//                holder.tvOriginPrice.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
//            } else {
//                holder.tvOriginPrice.setText("");
//            }
//            if (null != list.getViewnum() && !"".equals(list.getViewnum())) {
//                holder.tvView.setText(list.getViewnum());
//            } else {
//                holder.tvView.setText("");
//            }
//            if (null != list.getServicetime() && !"".equals(list.getServicetime())) {
//                holder.tvTime.setText(list.getServicetime() + "分钟");
//            } else {
//                holder.tvTime.setText("");
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        return convertView;
    }

    class ViewHolder {
        private ImageView ivImg;
        private TextView tvText;
        private TextView tvOriginPrice;
        private TextView tvRewardCoin;
        private TextView tvView;
        private TextView tvCash;
        private ImageView ivLimit;
        private TextView tvTime;
        private TextView yield_point;
    }
}
